package com.tjian.fafa.user.base;

import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Process;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.Toast;

import com.tjian.fafa.user.R;
import com.tjian.fafa.user.base.mainBody.MainBodyActivity;
import com.tjian.util.NetUtil;


public class Start_Activity extends Activity
{

    private boolean go_flage = true;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        requestWindowFeature(Window.FEATURE_NO_TITLE); //requestWindowFeature(Window.FEATURE_NO_TITLE); 这个在Android里用来隐藏标题栏的函数.
        super.onCreate(savedInstanceState);




        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }





        setContentView(R.layout.start_animation);
        ImageView tv = (ImageView) findViewById(R.id.appLogo_imageView);
        NetUtil.checkNetworkAndRemindingOpenNetwork(this);
        new Thread()
        {

            @Override
            public void run()
            {
                try
                {
                    Thread.sleep(1000);
                }
                catch (InterruptedException e)
                {
                    e.printStackTrace();
                }
                if (go_flage)
                {

                    //首页为登录页
                    /*Intent intent = new Intent(Start_Activity.this, MainActivity_login.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                    finish();*/


                    //首页为主页
                    Intent intent0 = new Intent(Start_Activity.this, MainBodyActivity.class);
                    //Intent中直接加入标志Intent.FLAG_ACTIVITY_CLEAR_TOP，再次开启A时将会清除该进程空间的所有Activity。
                    intent0.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent0);
                    finish();


                }

            }

        }.start();
    }

    //检查网络连接，如果没有打开网络连接，提醒打开网络,并退出程序；
    public void checkNetwork()
    {
        ConnectivityManager connManager = (ConnectivityManager) this.getSystemService(CONNECTIVITY_SERVICE);
        if (!connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected() &&
                !connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected())
        {
            go_flage = false;
            Builder builder = new Builder(Start_Activity.this);
            builder.setTitle("温馨提示").setMessage("目前网络未开通，请打开网络连接").setPositiveButton("确定", new OnClickListener()
            {
                @Override
                public void onClick(DialogInterface dialog, int which)
                {
                    Process process = new Process();
                    process.killProcess(process.myPid());
                }
            }).create().show();
        }
    }

    //检查网络连接并且提醒打开网络连接；
    /*public void checkNetworkAndRemindingOpenNetwork()
    {
        ConnectivityManager connManager = (ConnectivityManager) this.getSystemService(CONNECTIVITY_SERVICE);
        if( !connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected() &&
                !connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected())
        {
            Toast.makeText(this, "目前网络未开通，请打开网络连接", Toast.LENGTH_LONG).show();
        }
    }*/

}
